//uses jquery

var kavadenn = kavadenn || {};

kavadenn.PlacesService = function(community,handleGotData,beforeGettingData){
  this.data = [];
  this.handleGotData = handleGotData;
  this.beforeGettingData = beforeGettingData;
  this.community = community;
}

kavadenn.PlacesService.prototype.get = function(filter){
  if(this.beforeGettingData) this.beforeGettingData();
  
  $.post("/places/find/",{"community":this.community,"category":filter["category"]},
   this._bindCallback(function(d){
    if(this.handleGotData) this.handleGotData(d);
  }));
  return this.data;  
}

kavadenn.PlacesService.prototype._bindCallback = function(callback) {
    //utility method to bind callback methods to the object instance
    var objSelf = this;
    return (function() { return (callback.apply(objSelf, arguments)); });
}
